const Mock = require('mockjs')

const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
  id: '@increment',
  date: '@datetime',
  'deviceName|1': ['PLC_1','PLC_2'],
  IP: '@ip()',
  'MAC|1': ['02-1B-1B-9B-F3-02', '02-B8-2B-X0-F3-02', '3B-1B-1B-9F-F3-02', '58-0B-1B-9B-A2-02'],
  rack: '0',
  slot: '1',
  type: 'S7 1500',
  'status|1': ['启用','禁用'],
  'deviceStatus|1': ['在线','离线','故障'],
  description: '@title(5, 20)',

  }))
}


module.exports = [
  // {
  //   url: '/table/getWriteList',
  //   type: 'get',
  //   response: config => {
  //     return {
  //       code: 20000,
  //       data: {
  //         total: List.length,
  //         items: List
  //       }
  //     }
  //   }
  // },
  {
    url: '/device/getDeviceList',
    type: 'get',
    response: config => {
      const {  deviceName,deviceStatus, page = 1, limit = 20, sort } = config.query
      let mockList = List.filter(item => {

        if (deviceStatus && item.deviceStatus !== deviceStatus) return false
        if (deviceName && item.deviceName.indexOf(deviceName) < 0) return false

        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
]

